﻿using System.Data;
using System.Data.Common;
using ChinaDynastyTours.Models;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System;

namespace ChinaDynastyTours.Helpers
{
    class SMSHelper
    {
        public static bool SendSMSInfo(SendBufferEntity entity)
        {
            Database db = DatabaseFactory.CreateDatabase();

            string sql = string.Format(@"INSERT INTO WBS_SMS_SendBuffer(SenderId,SenderName,NChannel,MobileNo,SmsContent,NewFlag,SendTime,SendPriority,MobileNoType,PutType,ModemComNo,SmsType,RepeatCount,RepeatCurrtCount,Signature,PublicField1,PublicField2,HistoryId,StatusReport)
                                         VALUES(@SenderId,@SenderName,@NChannel,@MobileNo,@SmsContent,@NewFlag,@SendTime,@SendPriority,@MobileNoType,@PutType,@ModemComNo,@SmsType,@RepeatCount,@RepeatCurrtCount,@Signature,@PublicField1,@PublicField2,@HistoryId,@StatusReport)");
            DbCommand dbCommand = db.GetSqlStringCommand(sql);

            db.AddInParameter(dbCommand, "SenderId", DbType.String, entity.SenderId);
            db.AddInParameter(dbCommand, "SenderName", DbType.String, entity.SenderName);
            db.AddInParameter(dbCommand, "NChannel", DbType.String, entity.NChannel);
            db.AddInParameter(dbCommand, "HistoryId", DbType.Int32, DBNull.Value);//entity.HistoryId);
            db.AddInParameter(dbCommand, "MobileNo", DbType.String, entity.MobileNo);
            db.AddInParameter(dbCommand, "SmsContent", DbType.String, entity.SmsContent);
            db.AddInParameter(dbCommand, "NewFlag", DbType.Int32, entity.NewFlag);
            db.AddInParameter(dbCommand, "SendPriority", DbType.Int32, entity.SendPriority);
            db.AddInParameter(dbCommand, "SendTime", DbType.DateTime, entity.SendTime);
            db.AddInParameter(dbCommand, "MobileNoType", DbType.Int32, entity.MobileNoType);
            db.AddInParameter(dbCommand, "PutType", DbType.Int32, entity.PutType);
            db.AddInParameter(dbCommand, "SmsType", DbType.Int32, entity.SmsType);
            db.AddInParameter(dbCommand, "RepeatCount", DbType.Int32, entity.RepeatCount);
            db.AddInParameter(dbCommand, "RepeatCurrtCount", DbType.Int32, entity.RepeatCurrtCount);
            db.AddInParameter(dbCommand, "Signature", DbType.String, DBNull.Value);//entity.Signature);
            db.AddInParameter(dbCommand, "ModemComNo", DbType.Int32, entity.ModemComNo);
            db.AddInParameter(dbCommand, "PublicField1", DbType.String, DBNull.Value);//entity.PublicField1);
            db.AddInParameter(dbCommand, "PublicField2", DbType.String, DBNull.Value);//entity.PublicField2);
            db.AddInParameter(dbCommand, "StatusReport", DbType.Int32, entity.StatusReport);

            return db.ExecuteNonQuery(dbCommand)>0;
        }
    }
}
